﻿using Architeture.Domain;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC.ZhuBoLin.Application.Command.RoleCommand;
using RBAC.ZhuBoLin.Dtos;

namespace RBAC.ZhuBoLin.Controllers
{
    /// <summary>
    /// 县
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class CountyController : ControllerBase
    {
        protected readonly ICountyService countyservice;
        protected readonly IMediator mediator;

        public CountyController(ICountyService countyservice, IMediator mediator)
        {
            this.countyservice = countyservice;
            this.mediator = mediator;
        }


        /// <summary>
        /// 返回县级 （三级）
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<CountyInfo>>> GetCounty([FromQuery] CountySelectCommand sid)
        {
            ApiResult<List<CountyInfo>> result = new ApiResult<List<CountyInfo>>();
            try
            {
                result.Data = await mediator.Send(sid);
            }
            catch (Exception ex)
            {
                result.Code = 1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
    }
}
